package com.snowy.hidden.user.controller;


import com.snowy.framework.common.resp.BaseResp;
import com.snowy.framework.common.resp.BaseRespUtil;
import com.snowy.hidden.exception.SysErrorEnum;
import com.snowy.hidden.user.domain.model.SysUser;
import com.snowy.hidden.user.domain.req.UserListByRoleListReq;
import com.snowy.hidden.user.service.SysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@Api(tags = "角色")
@Slf4j
@RestController
@RequestMapping("/api/role")
public class RoleController {
    @Resource
    private SysRoleService sysRoleService;



    @ApiOperation("通过角色code集合查询人员列表")
    @PostMapping(value = "/getUserListByRoleCodeList")
    public BaseResp getUserListByRoleCodeList(@Valid @RequestBody UserListByRoleListReq userListByRoleListReq, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return BaseRespUtil.Error(SysErrorEnum.PARAM_ERROR.getReturnCode(), bindingResult.getAllErrors().get(0).getDefaultMessage());
        }
        try {
            List<SysUser> userList = sysRoleService.getUserListByRoleCodeList(userListByRoleListReq);
            return BaseRespUtil.Success(userList);
        } catch (Exception e) {
            return BaseRespUtil.Error(e);
        }
    }

}

